package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    @Select("select count(*) from setmeal where category_id=#{categoryId}")
    int countByCategoryId(Long categoryId);

    /**
     * 套餐分页
     * @param setmealPageDTO
     * @return
     */
    List<SetmealVO> findLIst(SetmealPageDTO setmealPageDTO);

    /**
     * 新增套餐 (先保存到套餐表)
     * @param setmeal
     */

    @AutoFill("insert")
    @Options(useGeneratedKeys = true,keyProperty = "id")  //主键返回
    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price},#{status},#{description},#{image}," +
            "#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void svae(Setmeal setmeal);

    /**
     * 回显套餐(因为要修改) 先查询套餐 + 分类名称
     * @param id
     * @return
     */
    @Select("select s.*,c.name as categoryName from " +
            "setmeal s left join category c on s.category_id = c.id where s.id = #{id}")
    SetmealVO findById(Long id);


    /**
     * 修改套餐  ----根据id修改套餐表 (先修改套餐)
     * @param setmeal
     */
    @AutoFill("update")
    void update(Setmeal setmeal);

    /**
     * 批量删除套餐
     * @param ids
     */
    void delete(List<Long> ids);


}






